<?php
header('Content-Type:text/html; charset=utf-8;');
$_run_time_start = microtime(1);

$key = empty($_GET['k']) ? '' : $_GET['k'];
$date = empty($_GET['d']) ? date('Ymd', time() - 86400) : $_GET['d'];
?>

<style>
body {font-size:14px;}
b {color:#fff;background:#f00;}
ol {line-height:22px;}
</style>
<form action="" method="GET">
	<input type="text" name="k" value="<?php echo $key?>" style="width:400px;" />
	<input type="text" name="d" value="<?php echo $date?>" />
	<input type="submit" value="搜索" />
</form>

<?php
$key_url = urlencode($key);

$doc = new DOMDocument();
//$url = "http://search.ifeng.com/sofeng/searchxml.action?t=$key_url&df=$date&dt=$date&n=500";
$url = "http://search.ifeng.com/sofeng/searchxml.action?title=$key_url&df=$date&dt=$date&n=500";
@$doc->load($url);
$items = $doc->getElementsByTagName('item');

/**
 * 输出
 * 
 * 
 */
echo '<b>'.$key.'</b> - ';
echo round(microtime(1) - $_run_time_start, 3).'s - ';
echo "<a href='$url' target='_blank'>$url</a>";

echo '<ol>';
foreach ($items as $item) {
	//原始数据
	$date = $item->getElementsByTagName('Doc_Date')->item(0)->nodeValue;
	$title = $item->getElementsByTagName('Doc_Title')->item(0)->nodeValue;
	$url = $item->getElementsByTagName('Doc_Url')->item(0)->nodeValue;
	//处理数据
	$title = str_replace($key, "<b>$key</b>", $title);
	
	echo "<li>$date <a href='$url' target='_blank'>$title</a>";
}
echo '</ol>';
?>